/*
 * @Author: whq
 * @Date: 2022-12-28 11:27:04
 * @LastEditTime: 2022-12-28 11:39:51
 * @LastEditors: whq
 * @Description: 
 * @FilePath: \vueTemp\src\router\index.ts
 */
import { createRouter, createWebHistory } from 'vue-router'
import routes from './routes'

const router = createRouter({
    history: createWebHistory(),
    routes
})

// 监听路由拦截
router.beforeEach((to, from, next) => {
    // 1. 每个条件执行后都要跟上 next() 或 使用路由跳转 api 否则页面就会停留一动不动
    // 2. 要合理的搭配条件语句，避免出现路由死循环。
    // const token = localStorage.getItem(import.meta.env.VITE_APP_TOKENNAME + 'token')
    // console.log('%c [ router.beforeEach ] 日志', 'font-size:13px; background:#26A08F; color:#fff;', "to:",to,"from:",from);
    // if (to.path != '/login') {
    //     if (!token) {
    //         next({ path: '/login' })
    //     }
    //     if(to.path == '/'){
    //         next({path: '/home'})
    //     }
    //    next()
    // } 

    if (to.path == '/') {
        next({ path: '/home' })
    }
    next()

})

export default router
